import 'package:get/get.dart';
import 'package:pull_to_refresh/src/smart_refresher.dart';
import 'package:testlzhu/bean/rent_bean.dart';
import 'package:testlzhu/data/net/http_manager.dart';
import 'package:testlzhu/utils/toast_show.dart';
//机械设备
class RentPageLogic extends GetxController {
  late RefreshController _refreshController;

  RentPageLogic(RefreshController refreshController) {
    _refreshController = refreshController;
  }

  void setController(RefreshController refreshController) {
    _refreshController = refreshController;
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  int posi = 1;

  var datas = <RentEquipments>[].obs;

  @override
  void onInit() {
    super.onInit();
    print('RentPageLogic');
    getData();
  }

  ///state   1 刷新 2 加载  0 默认
  void getData({String str = '', int state = 0}) {
    switch (state) {
      case 1:
        datas.clear();
        posi = 1;
        break;
      case 2:
        posi++;
        break;
      default:
        datas.clear();

        posi = 1;
        break;
    }

    var data = <String, dynamic>{};
    data['p'] = '$posi';
    data['q'] = str;
    data['ismapmode'] = '0';
    data['brandid'] = '0';
    data['centerlatitude'] = '31.242014';
    data['sortby'] = 'recommend';
    data['cat2id'] = '0';
    data['centerlongitude'] = '121.491259';
    HttpManager().get<RentBean>(
        url: 'equipment/index',
        params: data,
        success: (success) {
          if (success.equipments!.isNotEmpty) {
            var equipments = success.equipments;
            datas.addAll(equipments!);
          }
          update();
          _refreshController.refreshCompleted();
          _refreshController.loadComplete();
        },
        error: (error) {
          ToastShow.showToast(error.message);
          _refreshController.refreshCompleted();
          _refreshController.loadComplete();
        });
  }
}
